Copied from upstream:
https://hg.mozilla.org/releases/mozilla-esr38/raw-rev/a653013e7b50

# HG changeset patch
# User Peter Van der Beken <peterv@propagandism.org>
# Date 1454340035 -3600
# Node ID a653013e7b503912a32621e8da64a37171316588
# Parent  0d0d7e8292f7ecf5f1149d528c0524f04447c4ad
Bug 1243335 - report bad QName. r=sicking, a=sylvestre

diff --git a/dom/xslt/xslt/txInstructions.cpp b/dom/xslt/xslt/txInstructions.cpp
--- a/dom/xslt/xslt/txInstructions.cpp
+++ b/dom/xslt/xslt/txInstructions.cpp
@@ -93,16 +93,19 @@ txAttribute::txAttribute(nsAutoPtr<Expr>
                          txNamespaceMap* aMappings)
     : mName(Move(aName)), mNamespace(Move(aNamespace)), mMappings(aMappings)
 {
 }
 
 nsresult
 txAttribute::execute(txExecutionState& aEs)
 {
+    nsAutoPtr<txTextHandler> handler(
+        static_cast<txTextHandler*>(aEs.popResultHandler()));
+
     nsAutoString name;
     nsresult rv = mName->evaluateToString(aEs.getEvalContext(), name);
     NS_ENSURE_SUCCESS(rv, rv);
 
     const char16_t* colon;
     if (!XMLUtils::isValidQName(name, &colon) ||
         TX_StringEqualsAtom(name, nsGkAtoms::xmlns)) {
         return NS_OK;
@@ -125,19 +128,16 @@ txAttribute::execute(txExecutionState& a
         if (!nspace.IsEmpty()) {
             nsId = txNamespaceManager::getNamespaceID(nspace);
         }
     }
     else if (colon) {
         nsId = mMappings->lookupNamespace(prefix);
     }
 
-    nsAutoPtr<txTextHandler> handler(
-        static_cast<txTextHandler*>(aEs.popResultHandler()));
-
     // add attribute if everything was ok
     return nsId != kNameSpaceID_Unknown ?
            aEs.mResultHandler->attribute(prefix, Substring(name, lnameStart),
                                          nsId, handler->mValue) :
            NS_OK;
 }
 
 txCallTemplate::txCallTemplate(const txExpandedName& aName)

